import prompt from '@system.prompt';
import router from '@system.router';
import http from '@ohos.net.http';
export default {
    data: {
        title: "",
        users:{
            "name":"测试用户1",
            "password":"123456",
            "true_name":"Tom",
            "sex":1,
            "age":20,
            "phone":"18922561183"
        },
        result:""
    },
    onInit() {
        this.title = "Hello World";
    },
    onRadioChange(inputValue, e) {
        if(inputValue=="男"){
            this.users.sex=1
        }
        else{
            this.users.sex=2;
        }
        console.info('onRadioChange')
    },
    onName_change(e){
        this.users.true_name=e.value;
        console.info("YZJ"+JSON.stringify(e));
    },
    onAge_change(e){
        this.users.age=e.value
        console.info("YZJ"+JSON.stringify(e));
    },
    onPassword_change(e){
        this.users.password=e.value
        console.info("YZJ"+JSON.stringify(e));
    },
    onPhone_change(e){
        this.users.phone=e.value;
        console.info("YZJ"+JSON.stringify(e));
    },
    onAccount_change(e){
        this.users.name= e.value;
        console.info("YZJ"+JSON.stringify(e));
    },
    onRegister(){
       let httpRequest = http.createHttp();
        httpRequest.request(
            "https://www.xdsbty.cn/addUser",
            {
                method:http.RequestMethod.POST,
                header: {
                    'Content-Type': 'application/json'
                },
                extraData:{

                      "Name":this.users.name,
                      "Password":this.users.password,
                      "True_Name":this.users.true_name,
                      "Sex":this.users.sex,
                      "Age":parseInt(this.users.age),
                      "Phone":this.users.phone
                },
                readTimeout: 10000,
                connectTimeout: 10000,
            }, (err, data) => {
            if (!err) {
                console.info("YZJ--- "+JSON.stringify(data))
                this.result = JSON.parse(data.result);
                if(this.result.isSuccess==true){
                    router.push({
                        uri:"pages/login/login"
                    })
                }
                else{
                    prompt.showToast({
                        message:this.result.message
                    })
                }
                console.info("YZJ--- "+JSON.stringify(data.result))
            } else {
                console.info('YZJ--- error:' + JSON.stringify(err));

            }
        })
    }


}
